home *** CD-ROM | disk | FTP | other *** search
- include qlib.inc
- include stdlib.inc
-
- ; ADDED : v2.01
-
- ;striped right from BC v5.0 LIBs! (with some modification)
-
- .data
- s1 dw 0
- s2 dw 1
-
- .code
-
- srand proc,a:word
- mov ax,a
- mov s1,0
- mov s2,ax
- xor eax,eax
- ret
- srand endp
-
- rand proc
- pushad
- mov cx,s1
- mov bx,s2
- mov dx,015Ah
- mov ax,4E35h
-
- xchg ax,si
- xchg ax,dx
- test ax,ax
- jz @f
- mul bx
- @@:
- jcxz @f
- xchg ax,cx
- mul si
- add ax,cx
- @@:
- xchg ax,si
- mul bx
- add dx,si
-
- add ax,1
- adc dx,0
- mov s1,dx
- mov s2,ax
- popad
- xor eax,eax
- mov ax,s1
- and ax,7FFFh
- ret
- rand endp
-
- randomize proc uses edx ebx
- mov eax,gs:[46ch] ;timer tick
- inc eax
- mov ebx,gs:[41ah] ;kbd head/tail
- inc ebx
- mul ebx
- callp srand,ax
- xor eax,eax
- ret
- randomize endp
-
- random proc uses ebx edx,a:word
- ;returns random num from 0 to (a-1)
- callp rand
- mov bx,a
- xor edx,edx
- idiv bx
- xor eax,eax
- mov ax,dx
- ret
- random endp
-
- end
-
-